/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lvyh.lightframe.sample.controller.sms;

import com.lvyh.lightframe.sms.channel.aliyun.AliyunSmsPushProcessor;
import com.lvyh.lightframe.sms.channel.jdcloud.JdCloudSmsPushProcessor;
import com.lvyh.lightframe.sms.common.SmsMultipartContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lvyh 2021/03/21.
 */
@RestController
public class SmsPushController {

    @Autowired
    private AliyunSmsPushProcessor aliyunSmsPushProcessor;
    @Autowired
    private JdCloudSmsPushProcessor jdCloudSmsPushProcessor;

    //http://localhost:8080/aliyun-sms-push
    @RequestMapping("/aliyun-sms-push")
    public String sendMsg1() {
        SmsMultipartContent smsMsgContent = new SmsMultipartContent();
        smsMsgContent.setTemplateCode("ali");
        Map<String, String> templateParams = new HashMap<>();
        templateParams.put("name", "小陈");
        templateParams.put("code", "123456");
        smsMsgContent.setTemplateParams(templateParams);
        List<String> phones = Arrays.asList("18700002222");
        boolean result = aliyunSmsPushProcessor.sendMsg(smsMsgContent, phones);
        return "" + result;
    }

    //http://localhost:8080/jd-cloud-sms-push
    @RequestMapping("/jd-cloud-sms-push")
    public String sendMsg() {
        SmsMultipartContent smsMsgContent = new SmsMultipartContent();
        smsMsgContent.setTemplateCode("jd");
        Map<String, String> templateParams = new HashMap<>();
        templateParams.put("name", "小陈");
        templateParams.put("code", "123456");
        smsMsgContent.setTemplateParams(templateParams);
        List<String> phones = Arrays.asList("18700002222");
        boolean result = jdCloudSmsPushProcessor.sendMsg(smsMsgContent, phones);
        return "" + result;
    }
}